package com.gpframework.module.controller.ctn;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.core.page.TableDataInfo;
import com.gpframework.module.ctn.domain.GpPackagesInformation;
import com.gpframework.module.ctn.domain.req.GpPackagesInformationAdd;
import com.gpframework.module.ctn.domain.req.GpPackagesInformationReq;
import com.gpframework.module.ctn.domain.req.GpPackagesInformationUpdate;
import com.gpframework.module.ctn.domain.vo.GpPackagesInformationVo;
import com.gpframework.module.ctn.service.IGpPackagesInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
/**
 * @ClassName GpPackagesInformationController
 * @Author gpframework
 * @Date 2024-01-08
 * @Version 1.0.0
 * @Description 打包信息填写Controller 接口类
 */
@Validated
@Api(tags = "打包信息填写")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/ctn/packagesinformation" )
public class GpPackagesInformationController extends BaseController {

    private final IGpPackagesInformationService iGpPackagesInformationService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2024-01-08
  * @Param gpPackagesInformation
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @GetMapping("/list")
    public TableDataInfo<GpPackagesInformationVo> list(GpPackagesInformationReq gpPackagesInformationReq)
    {
        startPage();
        QueryWrapper<GpPackagesInformation> lqw = new QueryWrapper<GpPackagesInformation>();
        gpPackagesInformationReq.generatorQuery(lqw,true);
        List<GpPackagesInformationVo> list = iGpPackagesInformationService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2024-01-08
     * @Param gpPackagesInformation
     * @Return AjaxResult
     */
    @ApiOperation("详情")
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpPackagesInformationVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpPackagesInformationService.getVoById(id));
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2024-01-08
     * @Param gpPackagesInformation
     * @Return AjaxResult
     */
    @ApiOperation("新增")
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpPackagesInformationAdd gpPackagesInformationAdd) {
        GpPackagesInformation gpPackagesInformation = Convert.convert(new TypeReference<GpPackagesInformation>() {}, gpPackagesInformationAdd);
        if (gpPackagesInformationAdd.getPackagesInformationId()==null){
            return toAjax(iGpPackagesInformationService.save(gpPackagesInformation) ? 1 : 0);
        }
        gpPackagesInformation.setId(gpPackagesInformationAdd.getPackagesInformationId());
        return toAjax(iGpPackagesInformationService.updateById(gpPackagesInformation) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2024-01-08
     * @Param gpPackagesInformation
     * @Return AjaxResult
     */
    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpPackagesInformationUpdate gpPackagesInformationUpdate) {
        GpPackagesInformation gpPackagesInformation = Convert.convert(new TypeReference<GpPackagesInformation>() {}, gpPackagesInformationUpdate);
        return toAjax(iGpPackagesInformationService.updateById(gpPackagesInformation) ? 1 : 0);
    }

    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2024-01-08
     * @Param gpPackagesInformation
     * @Return AjaxResult
     */
    @ApiOperation("删除")
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpPackagesInformationService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
